package com.exam.controller;

import com.exam.entity.Admin;
import com.exam.entity.ApiResult;
import com.exam.serviceimpl.AdminServiceImpl;
import com.exam.util.ApiResultHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理员使用接口")
@RestController
public class AdminController {

    /*private AdminServiceImpl adminService;
    @Autowired
    public AdminController(AdminServiceImpl adminService){
        this.adminService = adminService;
    }*/
     @Resource
     AdminServiceImpl adminService;


    @ApiOperation(value = "查看所有管理员数据")
    @GetMapping("/admins")
    public ApiResult findAll(){
        return adminService.findAll();
    }

    @ApiOperation(value = "根据管理员的id查询对应的管理员的信息")
    @GetMapping("/admin/{adminId}")
    public ApiResult findById(@PathVariable("adminId") Integer adminId){
        return adminService.findById(adminId);
    }

    @ApiOperation(value = "根据管理员id删除管理员信息")
    @DeleteMapping("/admin/{adminId}")
    public ApiResult deleteById(@PathVariable("adminId") Integer adminId){
        return adminService.deleteById(adminId);
    }

    @ApiOperation(value = "根据ID和需要修改的数据进行修改" )
    @PutMapping("/admin/{adminId}")
    public ApiResult update(@PathVariable("adminId") Integer adminId, Admin admin){
        return adminService.update(admin);
    }

    @ApiOperation(value = "添加管理员信息")
    @PostMapping("/admin")
    public ApiResult add(Admin admin){
        return adminService.add(admin);
    }
}
